package com.ruoyi.huoyun.message.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.huoyun.message.domain.LeaveMessage;
import com.ruoyi.huoyun.message.service.ILeaveMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言Controller
 *
 * @author mj
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/message/leaveMessage")
public class LeaveMessageController extends BaseController
{
    @Autowired
    private ILeaveMessageService leaveMessageService;

    /**
     * 查询留言列表
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveMessage leaveMessage)
    {
        startPage();
        List<LeaveMessage> list = leaveMessageService.selectLeaveMessageList(leaveMessage);
        return getDataTable(list);
    }

    /**
     * 导出留言列表
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:export')")
    @Log(title = "留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaveMessage leaveMessage)
    {
        List<LeaveMessage> list = leaveMessageService.selectLeaveMessageList(leaveMessage);
        ExcelUtil<LeaveMessage> util = new ExcelUtil<LeaveMessage>(LeaveMessage.class);
        util.exportExcel(response, list, "留言数据");
    }

    /**
     * 获取留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:query')")
    @GetMapping(value = "/{leaveMessageId}")
    public AjaxResult getInfo(@PathVariable("leaveMessageId") String leaveMessageId)
    {
        return AjaxResult.success(leaveMessageService.selectLeaveMessageByLeaveMessageId(leaveMessageId));
    }

    /**
     * 新增留言
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:add')")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveMessage leaveMessage)
    {
        leaveMessage.setLeaveMessageId(System.currentTimeMillis() + "");
        return toAjax(leaveMessageService.insertLeaveMessage(leaveMessage));
    }

    /**
     * 修改留言
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:edit')")
    @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveMessage leaveMessage)
    {
        return toAjax(leaveMessageService.updateLeaveMessage(leaveMessage));
    }

    /**
     * 删除留言
     */
    @PreAuthorize("@ss.hasPermi('message:leaveMessage:remove')")
    @Log(title = "留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaveMessageIds}")
    public AjaxResult remove(@PathVariable String[] leaveMessageIds)
    {
        return toAjax(leaveMessageService.deleteLeaveMessageByLeaveMessageIds(leaveMessageIds));
    }
}
